package com.yc154.dao;

import com.yc.damai.entity.Promotion;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

public interface PromotionDao extends R2dbcRepository<Promotion, Long> {

    // 活动可以在 begin 一小时之前启动 : begin + INTERVAL -1 HOUR
    @Query("select * from promotion" +
            " where now() between begin + INTERVAL -1 HOUR and end and status = :status" +
            " order by id")
    Flux<Promotion> findCurrentByStatus(String status);


    @Query("update promotion set status = :status where id = :id")
    Mono<Void> updateStatus(long id, String status);

    @Query("select * from promotion" +
            " where DATEDIFF(begin, now()) <= 3" +
            " and status = '未开始'")
    Flux<Promotion> selectByBegin();

}
